﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace SimpleLiteForm
{
    public struct Screenshot
    {
        public string path;
        public DateTime time;
    }

    public class Presentation
    {
        /// <summary>
        /// title of the presentation
        /// </summary>
        private string _title;

        /// <summary>
        /// date of the presentation
        /// </summary>
        private DateTime _date;

        private DateTime _beginTime;
        private DateTime _endTime;

        private List<Screenshot> _screenshots;

        /// <summary>
        /// Creates a Presentation instance.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="time">The date.</param>
        public Presentation(string title, DateTime time)
        {
            _title = title;
            _date = new DateTime();
            _date = time;

            _beginTime = time;
            _endTime = time;//temp

            _screenshots = new List<Screenshot>();

        }

        public string getTitle()
        {
            return _title;
        }

        //public Dat

        public void setBeginEnd(DateTime begin, DateTime end)
        {
            _beginTime = begin;
            _endTime = end;
        }

        public void setEndTime(DateTime end)
        {
            _endTime = end;
        }

        public DateTime getBeginTime()
        {
            
            return _beginTime;
            
        }

        public DateTime getEndTime()
        {
            return _endTime;
        }

        public TimeSpan getTimeSpan()
        {
            return _endTime - _beginTime;
        }

        /// <summary>
        /// Write a presentation into the file
        /// </summary>
        /// <param name="sw">the stream writer</param>
        public void writeFile(StreamWriter sw)
        {
            //title
            //date
            //begin time
            //end time
            //num of screenshots
            //path...
            //enter
            sw.WriteLine(_title);
            sw.WriteLine(_date.ToShortDateString());
            sw.WriteLine(_beginTime.ToString());
            sw.WriteLine(_endTime.ToString());
            sw.WriteLine(_screenshots.Count);
            for (int index = 0; index < _screenshots.Count; index++)
            {
                sw.Write(_screenshots[index].time.ToString());
                sw.Write(";");
                sw.WriteLine(_screenshots[index].path);
            }
               
            sw.WriteLine();
            
        }

        //public List<Screenshot> getScreenshotList()
        //{
        //    return _screenshots;
        //}

        public Screenshot getScreenshot(int index)
        {
            return _screenshots[index];
        }

        public int getScreenshotsNum()
        {
            return _screenshots.Count;
        }

        /// <summary>
        /// get an array of one record of presentation.
        /// </summary>
        public string[] getRecord()
        {
            string[] record = { _title, _date.ToShortDateString()};
            return record;
        }

        public void addScreenshotPath(string path)
        {
            Screenshot ss = new Screenshot();
            ss.path = path;
            ss.time = DateTime.Now;
            _screenshots.Add(ss);
        }

        public void readScreenshotPath(string str)
        {
            Screenshot ss = new Screenshot();
            string[] data = str.Split(';');
            ss.time = DateTime.Parse(data[0]);
            ss.path = data[1];
            _screenshots.Add(ss);
        }

        
    }
}
